
import static org.hamcrest.CoreMatchers.equalTo;
import io.restassured.response.Response;

import java.io.IOException;
import java.util.*;

public class Test {

    //待测接口
    HashMap<String,String> interfaces;
    //项目部署地址
    private static String baseUrl = "http://124.220.18.48:8096";
    //appid
    private static String appID="wx3613a079e6a03343";
    //测试用例表名
    private static String zhuyan="接口测试用例-朱岩.xlsx";
    private static String lishuai="接口测试用例-李帅.xlsx";

    public Test(){
        interfaces = new HashMap<String,String>();
        interfaces.put("login","/auth/login");
        interfaces.put("logout","/logout");
        interfaces.put("WXlogin","/auth/wx/{appid}/login");
        interfaces.put("currentUserInfo","/auth/me");
        interfaces.put("addBackUser","/user/ms");
        interfaces.put("getUserList","/user/list");
        interfaces.put("getUserPhoneNumber","/wx/user/{appid}/phone");
        interfaces.put("addCounselor","/user/ms/counselor");
        interfaces.put("addSupervisor","/user/ms/supervisor");
        interfaces.put("getSupervisorList","/user/ms/supervisor/list");
        interfaces.put("getCounselorList","/user/ms/counselor/list");
        interfaces.put("updateSupervisor","/user/ms/supervisor");
        interfaces.put("updateCounselor","/user/ms/counselor");
        interfaces.put("deleteSupervisor","/user/ms/supervisor/{username}");
        interfaces.put("deleteCounselor","/user/ms/counselor/{username}");
        interfaces.put("banVisitor","/user/ban/{userId}");
        interfaces.put("updatePassword","/user/password");
        interfaces.put("updateUser","/user/update");
        interfaces.put("activeUser","/user/active/{id}");
        interfaces.put("updateMaxConsults","/user/maxconsults");
        interfaces.put("arrange","/arrange");
        interfaces.put("batchArrange","/arrange/batch");
        interfaces.put("searchArrange","/arrange/theday");
        interfaces.put("deleteArrange","/arrange/{id}");
    }

    public void test() throws IOException {
//        login_logout_test();
        login_userlist_test();
    }

    //用户登入->登出场景
    private void login_logout_test() throws IOException {
        //登入
        HashMap<String,Object> formParams  = excelUtils.getTestCase(2,zhuyan);
        Response response = RestAssuredHelper.postTest(baseUrl+interfaces.get("login"),formParams,new HashMap<>(),new HashMap<>());
        response.then().statusCode(200);
        String cookie = response.header("Set-Cookie").substring(11);
        RestAssuredHelper.setJSESSIONID(cookie);
        //登出
        response = RestAssuredHelper.postTest(baseUrl+interfaces.get("logout"),new HashMap<>(),new HashMap<>(),new HashMap<>());
        response.then().statusCode(302);
    }

    //登入-》获取用户列表
    private void login_userlist_test() throws IOException {
        //登入
        HashMap<String,Object> formParams = excelUtils.getTestCase(2,zhuyan);
        Response response = RestAssuredHelper.postTest(baseUrl+interfaces.get("login"),formParams,new HashMap<>(),new HashMap<>());
        response.then().statusCode(200);
        String cookie = response.header("Set-Cookie").substring(11);
        RestAssuredHelper.setJSESSIONID(cookie);
        //获取用户列表
        HashMap<String,Object> queryParams = excelUtils.getTestCase(31,zhuyan);
        response = RestAssuredHelper.getTest(baseUrl+interfaces.get("getUserList"),queryParams);
        response.then().statusCode(200)
                .body("result.findAll.roles",equalTo("ROLE_VISITOR"));
    }




    public static void main(String[] args) throws IOException {
        new Test().test();
    }
}
